#include "stdafx.h"
#include "Graphics.h"

#define ALLEGRO_USE_CONSOLE
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>

const unsigned int kWidth = 800;
const unsigned int kHeight = 600;

/*static*/	std::shared_ptr<Graphics>	Graphics::_instance = NULL;

Graphics::Graphics(void): _display( NULL )
{
}


Graphics::~Graphics(void)
{
}

Graphics& Graphics::getGraphics() {
    if (!_instance) {
        _instance.reset( new Graphics );


    }

    return *_instance;
}

int Graphics::initialize() {
	if(!al_init()) {
		fprintf(stderr, "failed to initialize allegro!\n");
		return -1;
	}

	al_init_image_addon();
	al_init_primitives_addon();

	// Display setup
   al_set_new_display_flags( ALLEGRO_WINDOWED );
   _display = al_create_display(kWidth, kHeight);
   if(!_display) {
      fprintf(stderr, "failed to create display!\n");
      return -1;
   }
 
   al_clear_to_color(al_map_rgb(0,0,0));

	return 0;
}

int Graphics::step( float stepLength/* = .05*/ ) {
    al_flip_display();
    al_rest( stepLength );
    
    return 0;
}

int Graphics::finalize() {
    al_destroy_display( _display );
    
    return 0;
}

void Graphics::drawCenterLines() {
	//{400, 300};
	al_draw_line( 0, 300, 800, 300, al_map_rgb( 255, 255, 255 ), 1 );
	al_draw_line( 400, 0, 400, 600, al_map_rgb( 255, 255, 255 ), 1 );
}